package com.kit.data.kitopeso.dialog;

import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.kit.data.kitopeso.base.BaseDialog;
import com.kit.data.kitopeso.databinding.KitoToastDialogBinding;

public class ToastDialog extends BaseDialog<KitoToastDialogBinding> {
    public ToastDialog(@NonNull Context context) {
        super(context);
    }

    public ToastDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected ToastDialog(@NonNull Context context, boolean cancelable, @Nullable DialogInterface.OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected KitoToastDialogBinding initViewBinding(LayoutInflater inflater) {
        return KitoToastDialogBinding.inflate(inflater);
    }

    @Override
    protected void initView() {
        setCanceledOnTouchOutside(true);
        if (binding != null) {
            binding.getRoot().setOnClickListener(v -> dismiss());
        }
    }

    @Override
    public void show() {
        super.show();
        if (binding != null) {
            binding.tvTitle.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (binding != null && isShowing()) {
                        dismiss();
                    }
                }
            }, 2000);
        }
    }

    public void setTitle(String txt) {
        binding.tvTitle.setText(txt);
    }

    public void setIcon(int id) {
        if (binding != null) {
            binding.tvIcon.setImageResource(id);
        }
    }

}